package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.PayoutRecord;
import com.sxkf.template.service.PayoutRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-12-03 20:05:24
 */
@Api(tags = "提现模块")
@RestController
@RequestMapping("/payoutRecord")
public class PayoutRecordController {
    @Resource
    private PayoutRecordService payoutRecordService;

    @ApiOperation(value = "查询用户提现记录")
    @GetMapping(value = "/page")
    public R<IPage<PayoutRecord>> page(@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestParam String userId){
        Page<PayoutRecord> page = payoutRecordService.page(new Page<>(pageNo, pageSize), new LambdaQueryWrapper<PayoutRecord>()
                .eq(PayoutRecord::getUserId, userId).orderByDesc(PayoutRecord::getCreateTime));
        return R.success(page);
    }

    @ApiOperation(value = "申请提现")
    @PostMapping(value = "/apply")
    public R<?> apply(@RequestBody PayoutRecord payoutRecord){
        payoutRecordService.apply(payoutRecord);
        return R.success();
    }

    @ApiOperation(value = "驳回")
    @PostMapping(value = "/rejected")
    public R<?> rejected(@RequestBody PayoutRecord payoutRecord){
        payoutRecordService.rejected(payoutRecord.getId());
        return R.success();
    }

    @ApiOperation(value = "通过")
    @PostMapping(value = "/pass")
    public R<?> pass(@RequestBody PayoutRecord payoutRecord){
        payoutRecordService.pass(payoutRecord.getId());
        return R.success();
    }
}
